/*
 * 
 * Libman
 * 
 * Daniel Kaufmann, Martin Lang, Simon Moosbrugger,
 * Stefan Mayer, Stephan Halbeisen
 * 
 */
package model.dao;

import hibernate.HibernateUtil;

import java.util.List;

import model.Keyword;

import org.hibernate.Session;
import org.hibernate.criterion.Disjunction;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;

/**
 * A DAO implementation for Loan objects.
 */

public class KeywordDAO extends GenericHibernateDAO<Keyword, Long> {
	// implementation in parent class
	/**
	 * Gets the keywords.
	 * 
	 * @param words
	 *            the words
	 * @return the keywords
	 */
	public List<Keyword> getKeywords(String[] words) {

		Session session = HibernateUtil.currentSession();
		Disjunction crit = Restrictions.disjunction();

		for (String string : words) {
			crit.add(Restrictions.like("keyword", string, MatchMode.ANYWHERE));
		}

		@SuppressWarnings("unchecked")
		List<Keyword> keywordList = session.createCriteria(Keyword.class)
				.add(crit).list();

		return keywordList;
	}
}